var xhr;
var pages = new Array("home_index","music_index","home_contact");

self.onmessage = function(e) {
    for (var i = 0;i < pages.length; i++) {
        //Check if page_action is already in ajax_cache
        if(!(pages[i] in e.data)) {
            xhr = new XMLHttpRequest();   
            var split = pages[i].split('_');
            var url = "../controller/controller.php?page=" + split[0] + "&action=" + split[1];
            xhr.open('POST', url, false);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    self.postMessage({page_action: pages[i], content: xhr.responseText});
                }
            };
            xhr.send();
        }
    }
    self.close();
}